package com.erp.shop.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.erp.shop.service.IErpSellerStorePromotionActivityProductService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;

import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.core.utils.oldUtils.StringUtils;
import com.ruoyi.shop.api.domain.bo.ErpSellerStorePromotionActivityProductBo;
import com.ruoyi.shop.api.domain.vo.ErpSellerStorePromotionActivityProductVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 商家促销活动商品
 *
 * @author erp
 * @date 2023-06-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerStorePromotionActivityProduct")
public class ErpSellerStorePromotionActivityProductController extends BaseController {

    private final IErpSellerStorePromotionActivityProductService iErpSellerStorePromotionActivityProductService;

    /**
     * 查询商家促销活动商品列表
     */
    @SaCheckPermission("seller:sellerStorePromotionActivityProduct:list")
    @GetMapping("/list")
    public TableDataInfo<ErpSellerStorePromotionActivityProductVo> list(ErpSellerStorePromotionActivityProductBo bo, PageQuery pageQuery) {
        return iErpSellerStorePromotionActivityProductService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取商家促销活动商品详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("seller:sellerStorePromotionActivityProduct:query")
    @GetMapping("/{id}")
    public R<ErpSellerStorePromotionActivityProductVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpSellerStorePromotionActivityProductService.queryById(id));
    }

    /**
     * 新增商家促销活动商品
     */
    @SaCheckPermission("seller:sellerStorePromotionActivityProduct:add")
    @Log(title = "商家促销活动商品", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerStorePromotionActivityProductBo bo) {
        return toAjax(iErpSellerStorePromotionActivityProductService.insertByBo(bo));
    }

    /**
     * 修改商家促销活动商品
     */
    @SaCheckPermission("seller:sellerStorePromotionActivityProduct:edit")
    @Log(title = "商家促销活动商品", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerStorePromotionActivityProductBo bo) {
        return toAjax(iErpSellerStorePromotionActivityProductService.updateByBo(bo));
    }

    /**
     * 删除商家促销活动商品
     *
     * @param ids 主键串
     */
    @SaCheckPermission("seller:sellerStorePromotionActivityProduct:remove")
    @Log(title = "商家促销活动商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerStorePromotionActivityProductService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
